package it.polimi.comorazio.data;

import it.polimi.comorazio.R;
import it.polimi.comorazio.data.DataBaseHelper.ArchitectsImages;

import java.util.Arrays;
import java.util.List;

import android.content.res.Resources;
import android.database.Cursor;
import android.util.Log;

public class ImageVo {
	private String imageName;

	public ImageVo(Cursor c, int position) {
		c.moveToPosition(position);
		List<String> columns = Arrays.asList(c.getColumnNames());
		imageName = c.getString(columns
				.indexOf(ArchitectsImages.COLUMN_IMAGE_NAME));
	}

	@Override
	public String toString() {
		return "ImageVo [imageName=" + imageName + "]";
	}

	public String getImageName() {
		return imageName;
	}

	public void setImageName(String imageName) {
		this.imageName = imageName;
	}

	public int getImageIdentifier(Resources resourcesBundle) {
		int resourceId = resourcesBundle.getIdentifier(imageName, "drawable",
				"it.polimi.comorazio");

		if (resourceId == 0) {
			Log.d(this.getClass().getSimpleName(), "Image [" + imageName
					+ "] not found. Using default image.");
			resourceId = R.drawable.not_found;
		}

		return resourceId;
	}
}
